package text;

import java.text.DateFormat;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.ResourceBundle;

/**
 * 消息格式化演示
 * @author fidel
 *
 */
public class MessageFormatDemo {
    public static void main(String[] args) {
        ResourceBundle bundle = ResourceBundle.getBundle("CharactersFileDemo", Locale.CHINA);
        String pattern = bundle.getString("placeholder");
        MessageFormat messageFormat = new MessageFormat(pattern);
        Calendar calendar = Calendar.getInstance(Locale.CHINA);
        Date date = calendar.getTime();
        // 获取具有默认格式化风格的日期/时间格式化器，用于默认的格式化locale
        DateFormat dateFormat = SimpleDateFormat.getDateTimeInstance();
        String text = dateFormat.format(date);
        // 用指定的替换序列替换这个字符串中与字面目标序列匹配的每个子串
        String value = messageFormat.format(new Object[] { "fidel", text.replace(" ", "") });
        System.out.println(value);
    }
}
